package com.jzo2o.foundations.controller.operation;

import com.jzo2o.common.model.PageResult;
import com.jzo2o.common.model.Result;
import com.jzo2o.foundations.model.dto.request.ServePageQueryReqDTO;
import com.jzo2o.foundations.model.dto.request.ServeUpsertReqDTO;
import com.jzo2o.foundations.model.dto.response.ServeResDTO;
import com.jzo2o.foundations.service.IServeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.List;

/**
 * @author itlxc
 * @since 2024-10-11
 */
@RestController("operationServeController")
@RequestMapping("/operation/serve")
@Slf4j
@Api(tags = "运营端 - 区域服务相关接口")
@RequiredArgsConstructor
public class ServeController {

    private final IServeService serveService;

    @GetMapping("/page")
    @ApiOperation("区域服务分页查询")
    public PageResult<ServeResDTO> page(@Validated ServePageQueryReqDTO servePageQueryReqDTO) {
        log.info("区域服务分页查询参数：{}", servePageQueryReqDTO);
        return serveService.page(servePageQueryReqDTO);
    }

    @PostMapping("/batch")
    @ApiOperation("区域服务批量新增")
    public Result addBatch(@NotNull(message = "参数不能为空") @RequestBody List<ServeUpsertReqDTO> serveUpsertReqDTOS) {
        log.info("区域服务批量新增参数：{}", serveUpsertReqDTOS);
        serveService.addBatch(serveUpsertReqDTOS);
        return Result.ok();
    }

    @PutMapping("/{id}")
    @ApiOperation("区域服务价格修改")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "服务id", required = true, dataTypeClass = Long.class),
            @ApiImplicitParam(name = "price", value = "价格", required = true, dataTypeClass = BigDecimal.class)
    })
    public Result update(@NotNull(message = "参数不能为空") @PathVariable("id") Long id,
                         @NotNull(message = "价格不能为空") @RequestParam("price") BigDecimal price) {
        log.info("区域服务价格修改参数：id={}, price={}", id, price);
        serveService.updatePrice(id, price);
        return Result.ok();
    }

    @PutMapping("/onSale/{id}")
    @ApiOperation("区域服务上架")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "服务id", required = true, dataTypeClass = Long.class),
    })
    public Result onSale(@NotNull(message = "参数不能为空") @PathVariable("id") Long id) {
        log.info("区域服务上架参数：id={}", id);
        serveService.onSale(id);
        return Result.ok();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("区域服务删除")
    public Result delete(@NotNull(message = "参数不能为空") @PathVariable Long id) {
        log.info("区域服务删除参数：id={}", id);
        serveService.delete(id);
        return Result.ok();
    }

    @PutMapping("/offSale/{id}")
    @ApiOperation("区域服务下架")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "服务id", required = true, dataTypeClass = Long.class),
    })
    public Result offSale(@NotNull(message = "参数不能为空") @PathVariable("id") Long id) {
        log.info("区域服务下架参数：id={}", id);
        serveService.offSale(id);
        return Result.ok();
    }

    @PutMapping("onHot/{id}")
    @ApiOperation("区域服务设为热门")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "服务id", required = true, dataTypeClass = Long.class),
    })
    public Result onHot(@NotNull(message = "参数不能为空") @PathVariable("id") Long id) {
        log.info("区域服务设为热门参数：id={}", id);
        serveService.onHot(id);
        return Result.ok();
    }

    @PutMapping("offHot/{id}")
    @ApiOperation("区域服务取消热门")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "服务id", required = true, dataTypeClass = Long.class),
    })
    public Result offHot(@NotNull(message = "参数不能为空") @PathVariable("id") Long id) {
        log.info("区域服务取消热门参数：id={}", id);
        serveService.offHot(id);
        return Result.ok();
    }
}
